package com.oa.srms.apps.business.student.impl;

import java.io.FileInputStream;
import java.sql.Blob;
import java.util.List;

import org.hibernate.Hibernate;
import org.springframework.beans.factory.annotation.Autowired;
import com.oa.srms.apps.business.student.IAvatarInfoService;
import com.oa.srms.apps.dao.student.IAvatarInfoDao;
import com.oa.srms.apps.entity.student.AvatarInfoValue;

public class AvatarInfoServiceImpl implements IAvatarInfoService {
	@Autowired
	private AvatarInfoValue avatarInfoValue;
	@Autowired
	private IAvatarInfoDao avatarInfoDao;
	
	@Override
	public Integer addAvatarInfo(FileInputStream avatarImage, Integer avatarSize,
			String avatarType) throws Exception {
		if(avatarImage != null){
			Blob photo=Hibernate.createBlob(avatarImage, avatarSize);
			avatarInfoValue.setAvatarImage(photo);
			avatarInfoValue.setAvatarType(avatarType);
		}
		avatarInfoValue.setAvatarSize(avatarSize);
		return avatarInfoDao.addAvatarInfo(avatarInfoValue);
	}

	@Override
	public void modifyAvatarInfo(Integer avatarId, FileInputStream avatarImage,
			Integer avatarSize, String avatarType) throws Exception {
		avatarInfoValue=this.queryByAvatarId(avatarId);
		if(avatarInfoValue!=null){
			Blob photo=Hibernate.createBlob(avatarImage, avatarSize);
			avatarInfoValue.setAvatarImage(photo);
			avatarInfoValue.setAvatarSize(avatarSize);
			avatarInfoValue.setAvatarType(avatarType);
			avatarInfoDao.editAvatarInfo(avatarInfoValue);
		}
	}

	@Override
	public AvatarInfoValue queryByAvatarId(Integer avatarId) throws Exception {
		return avatarInfoDao.queryByAvatarId(avatarId);
	}

	@Override
	public List<AvatarInfoValue> queryAvatarInfo() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
